package com.lijin.mapper;


import com.lijin.entity.User;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

/**
 * Created by gold-jx on 2017/5/31.
 */
@Mapper
public interface UserMapper {


    /**
     * 增加，返回个数
     * @param user
     * @return
     */

    public int insert(User user);


    /**
     * 增加
     * @param user
     */
    @Insert("insert into user(name,age,sex) values(#{name},#{age},#{sex}) ")
    public void add(User user);


    /**
     * 根据id删除
     * @param name
     */
    @Delete("DELETE FROM user WHERE name = #{name} ")
    public void deleteByName(String name);


    /**
     * 根据名字修改
     * @param user
     */
    @Update("UPDATE user SET age=#{age},sex=#{sex} WHERE name=#{name}")
    public void updateById(User user);


    /**
     * 根据姓名查找
     * @param name
     * @return
     */
    @Select("select * from user where name=#{name}")
    @Results({
            @Result(column="id",property="id"),
            @Result(column="name",property="name"),
            @Result(column="age",property="age"),
            @Result(column="sex",property="sex")
    })
    public User findByName(String name);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from user ")
    @Results({
            @Result(column="id",property="id"),
            @Result(column="name",property="name"),
            @Result(column="age",property="age"),
            @Result(column="sex",property="sex")
    })
    public List<User> findAll();



}
